import { changeColor, genId } from "../utils/index";
export default function px2css({ main, position = "center"}) {
  const { pxMap, width, height } = main;
  let size = 1;
  let backgroundColor = "background-color:";
  let str = `
  width:${size}px;
  height:${size}px;
  box-shadow:`;
  let left = 0,
    top = 0;
  let className = `.px-${genId(2)}`;
  if (position == "center") {
    left = ~~((width * size) / 2);
    top = ~~((height * size) / 2);
  }
  pxMap.forEach((point, index) => {
    let x = point.x - left;
    let y = point.y - top;
    let color = changeColor(point.color);
    let tab = index == pxMap.length - 1 ? ";" : ",";
    if (x == 0 && y == 0) {
      backgroundColor += color + ";";
    }
    str += `${x}px ${y}px 0 ${color}${tab}`;
  });
  str += backgroundColor;

  let classContent = `${className}{${str}
}`;

  return classContent;
}
